package com.huzz.util.desin.flyweight;

import java.util.HashMap;
import java.util.Map;

class TrainFactory {
    private static Map<String, Train> trains = new HashMap<>();

    public static Train getTrain(String name, int capacity) {
        String key = name + "_" + capacity;
        if (!trains.containsKey(key)) {
            System.out.println("Creating new train " + key);
            Train train = new Train(name, capacity);
            trains.put(key, train);
        } else {
            System.out.println("Reusing existing train " + key);
        }
        return trains.get(key);
    }

}
